package srms.the505div1;

import java.util.ArrayList;

public class SetMultiples_Bad {

	public long smallestSubset(long a, long b, long c, long d) {
		long l = (b - a + 1) + (d - c + 1);
		long[] sList = null;
		if (l < Integer.MAX_VALUE)
			sList = new long[(int) l];
		ArrayList<Long> lfList = new ArrayList<Long>();

		for (long i = a; i <= b; i++) {
			sList[(int) (i - a)] = i;
		}
		for (long i = c; i <= d; i++) {
			sList[(int) (i - c + (b - a + 1))] = i;
		}

		int i;
		for (i = sList.length - 1; i >= 0; i--) {
			long x = sList[i];
			if (lfList.contains(x))
				break;
			for (int j = 0; j < sList.length; j++) {
				long x0 = sList[j];
				if (x % x0 == 0)
					lfList.add(x0);
			}
		}
		return sList.length - i - 1;
	}
}
